package com.zhou.juc.test06_AtomicXXX;

import com.zhou.juc.test03_volatile.TestVolatile;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author zhouyanxiang
 * @create 2020-08-2020/8/11-17:08
 */
public class T01_AtomicInteger {



    /*volatile*/ AtomicInteger  count = new AtomicInteger(0);

    public /*synchronized*/ void m(){
        for (int i = 0; i < 10000; i++) {
            count.incrementAndGet();
        }
    }

    public static void main(String[] args) {
      T01_AtomicInteger t = new T01_AtomicInteger();

        List<Thread> threads = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            threads.add(new Thread(t::m,"thread---" + i));
        }

        threads.forEach((o)->o.start());

        threads.forEach((o)->{
            try {
                o.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });

        System.out.println(t.count);
    }

}
